#include "configdata.h"

ConfigData::ConfigData()
{
    this->Initialize();
}

ConfigData::~ConfigData()
{
}

void ConfigData::Initialize()
{
    m_tranList = new TTranSetting[N_TRANSACTIONS];
    m_duration = 0;
    m_incUser = 0;
    m_incTime = 0;
    m_genList = new TGenConfig[MaxGenCount];
}

int ConfigData::addGen(std::string ip, int userCount)
{
    // find an availabel index
    int i;
    for(i = 0; i < MaxGenCount; i ++){
        if(m_genList[i].ip == "") break; // ip="" marks it as available
    }

    if(i < MaxGenCount){
        m_genList[i].ip = ip;
        m_genList[i].userCount = userCount;
        return i;
    }
    return -1;
}

void ConfigData::delGen(int genId)
{
    if(genId < MaxGenCount){
        m_genList[genId].ip = "";
        m_genList[genId].isOn = false;
        m_genList[genId].userCount = 0;
    }
}

void ConfigData::setGenConfig(int genId, const TGenConfig &config)
{
    m_genList[genId] = config;
}

void ConfigData::setTranSetting(int tranType, const TTranSetting &setting)
{
    m_tranList[tranType] = setting;
}

TGenConfig ConfigData::getGenConfig(int genId)
{
    return m_genList[genId];
}

TTranSetting ConfigData::getTranSetting(int tranType)
{
    return m_tranList[tranType];
}

int ConfigData::getDuration()
{
        return m_duration;
}

void ConfigData::setDuration(int duration)
{
        m_duration = duration;
}

int ConfigData::getIncUser()
{
        return m_incUser;
}

void ConfigData::setIncUser(int user)
{
        m_incUser = user;
}

int ConfigData::getIncTime()
{
        return m_incTime;
}

void ConfigData::setIncTime(int sec)
{
        m_incTime = sec;
}
